package com.fyl.pattern.state.before;

public class Lift implements ILift {
    //声明一个变量记录当前电梯的状态
    private int state;

    @Override
    public void setState(int state) {
        this.state = state;
    }

    @Override
    public void open() {
        switch (state) {
            case OPENING_STATE:
                //什么都不做
                break;
            case CLOSING_STATE:
                System.out.println("电梯打开了");
                this.setState(OPENING_STATE);
                break;
            case RUNNING_STATE:
                //什么都不做
                break;
            case STOPPING_STATE:
                System.out.println("电梯打开了");
                this.setState(OPENING_STATE);
                break;
                default:
        }
    }

    @Override
    public void close() {
        switch (state) {
            case OPENING_STATE:
                System.out.println("电梯关门了");
                this.setState(CLOSING_STATE);
                break;
            case CLOSING_STATE:
                //什么都不做
                break;
            case RUNNING_STATE:
                //什么都不做
                break;
            case STOPPING_STATE:
                //什么都不做
                break;
            default:
        }

    }

    @Override
    public void run() {
        switch (state) {
            case OPENING_STATE:
                //什么都不做
                break;
            case CLOSING_STATE:
                System.out.println("电梯开始运行了");
                this.setState(RUNNING_STATE);
                break;
            case RUNNING_STATE:
                //什么都不做
                break;
            case STOPPING_STATE:
                System.out.println("电梯开始运行了");
                this.setState(RUNNING_STATE);
                break;
            default:
        }
    }

    @Override
    public void stop() {
        switch (state) {
            case OPENING_STATE:
                //什么都不做
                break;
            case CLOSING_STATE:
                System.out.println("电梯停止了");
                this.setState(STOPPING_STATE);
                break;
            case RUNNING_STATE:
                System.out.println("电梯停止了");
                this.setState(STOPPING_STATE);
                break;
            case STOPPING_STATE:
                //什么都不做
                break;
            default:
        }
    }
}
